<template>
	<view class="login-container">
		<view class="login-box">
			<text class="login-title">注册</text>
			<view class="input-item">
				<input type="text" placeholder="请输入用户名" v-model="username" />
			</view>
			<view class="input-item">
				<input password="true" placeholder="请输入密码" v-model="password" />
			</view>
			<view class="input-item">
				<input password="true" placeholder="再次输入密码" v-model="confirmPassword" />
			</view>
			<button class="login-btn" @click="toLogin">注册</button>
			<view class="register-tip">
				已有账号？<text class="register-link" @click="toLogin">去登录</text>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "Login",
		data() {
			return {
				username: undefined,
				password: undefined,
				confirmPassword: undefined,
			};
		},
		methods: {
			toLogin() {
				if(!this.username){
					uni.showModal({
						title: "提示",
						content: "请输入用户名",
						showCancel: false,
					});
					return;
				}
				
				if(!this.username){
					uni.showModal({
						title: "提示",
						content: "请输入密码",
						showCancel: false,
					});
					return;
				}
				// 密码一致性校验
				if (this.password !== this.confirmPassword) {
					uni.showModal({
						title: "提示",
						content: "两次密码输入不一致",
						showCancel: false,
					});
					return;
				}

				uni.navigateTo({
					url: '/pages/LoginPage/LoginPage'
				})
			},
			
			toLogin(){
				uni.redirectTo({
					url:'/pages/LoginPage/LoginPage'
				})
			}
		},
	};
</script>

<style scoped>
	.login-container {
		display: flex;
		justify-content: center;
		align-items: center;
		min-height: 100vh;
		background-color: #f5f5f5;
	}

	.login-box {
		width: 80%;
		max-width: 400px;
		background-color: #fff;
		padding: 24px;
		border-radius: 8px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
	}

	.login-title {
		display: block;
		text-align: center;
		font-size: 20px;
		font-weight: bold;
		margin-bottom: 24px;
	}

	.input-item {
		margin-bottom: 16px;

	}

	.input-item input {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		border: 1px solid #ddd;
		border-radius: 4px;
		box-sizing: border-box;
		padding-left: 10rpx;
	}

	.login-btn {
		width: 100%;
		background-color: #007aff;
		color: #fff;
		border-radius: 4px;

	}

	.register-tip {
		text-align: center;
		margin-top: 16px;
		font-size: 14px;
		color: #666;
	}
	
	 

	.register-link {
		color: #007aff;
	}
</style>